<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<c:set var="ctx" value="${pageContext.request.contextPath }"></c:set>
	</head>
 <body>
 	<p>
 		<a href="${ctx }/test/afters">查询售后信息</a>
 	</p>
 	<p>
 		<a href="${ctx }/driver/selectAllDriver">查询驾驶员信息</a>
 	</p>
 	<p>
 		<!-- 图片回显 -->
 		<input type="file" id="fil">
 	</p>
 	<p>
 		<!-- ssm上传单个图片 -->
 		<form id="test">    
		    选择文件:<input data-role="none" type="file" name="file" width="120px">    
		    <button data-role="none" onclick="testUpload();">测试</button>  
		</form>  
 	</p>
 	
 	<p>
 		<!-- ssm上传两张张图片 -->
 		<form id="test2">    
		    选择文件1:<input data-role="none" type="file" name="file" width="120px">  <br>
		    
		      选择文件2:<input data-role="none" type="file" name="file" width="120px">      
		    <button data-role="none" onclick="test2Upload();">测试</button>  
		</form>  
 	</p>
 	<p>
 		<form action="${ctx }/demo/test" method="post">
 			初始册号：<input type="text" name="chuce">
	 		结束册号：<input type="text" name="jiece"><br>
	 		初始单据：<input type="text" name="chudan">
	 		结束单据：<input type="text" name="jiedan"><br>
	 		<input type="submit">
 		</form>
 		
 	</p>
 </body>
 <script src="<%=request.getContextPath()%>/resources/js/jquery-1.7.min.js" type="text/javascript" charset="utf-8"></script>
 <script type="text/javascript">
 		function testUpload(){
			var form = new FormData(document.getElementById("test"));
			
			$.ajax({
				url : '<%=basePath%>file/test.do',
				data : form,
				type : 'post',
				processData:false,
		        contentType:false,
		        success : function(data){
		        	alert("成功")
		        },
		        error : function(data){
		        	
		        }
			});
		}
 
 
 </script>
 
 
  <script type="text/javascript">
 		function testUpload(){
			var form = new FormData(document.getElementById("test2"));
			
			$.ajax({
				url : '<%=basePath%>file/test1.do',
				data : form,
				type : 'post',
				processData:false,
		        contentType:false,
		        success : function(data){
		        	alert("成功")
		        },
		        error : function(data){
		        	
		        }
			});
		}
 
 
 </script>
 
 <script type="text/javascript">   
   $(function(){  
     var fil=$("#fil");  
     $("<img>").insertAfter("input");  
     fil.bind('change',function(){  
         var fordate=new FormData();  //得到一个FormData对象：
         var fils=$("#fil").get(0).files[0];  //得到file对象
         console.log(fils);
         fordate.append('pic',fils);  //用append方法添加键值对
         var srcc=window.URL.createObjectURL(fils);     //传入的参数创建一个指向该参数对象的URL
         console.log(srcc);   
         $("img").attr({'src':srcc,'width':100+'px','heigth':100+'px'});  
         $.ajax({  //发送ajax请求
              url: "index4.php",  
              type: "post",  
              data: fordate,  
              processData : false,  
              contentType : false,   
              success: function(html){  
                console.log(html);  
              }  
            });  

     });  
    });  
  </script>  
</html>
